using DynConDevCorp.OpenArch.SmartData.Core;
using DynConDevCorp.OpenArch.SmartData.Core.Metadata;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using DynConDevCorp.OpenArch.SmartData.Interfaces;
using UnitTest.DynConDevCorp.OpenArch.SmartData.Unit_Tests;

namespace UnitTest.DynConDevCorp.OpenArch.SmartData
{
    [TestClass]
    public class MetaEntity_UnitTests
    {


        private TestContext testContextInstance;

        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        ////[TestMethod]
        ////[DeploymentItem("DynConDevCorp.OpenArch.SmartData.Core.dll")]
        ////public void WireEvents_UnitTest()
        ////{
        ////    Type targetType = typeof(TestSmartEntity); 
        ////    const string targetMethodName = "OnValueChanged";
        ////    object targetInstance = new TestSmartEntity();
        ////    Type sourceType = typeof(ISmartField<int>);
        ////    const string sourceEventName = "ValueChanged"; 
        ////    object sourceInstance = new SmartField<int>(); 
        ////    MetaEntity_Accessor.WireEvents(targetType, targetMethodName, targetInstance, sourceType, sourceEventName, sourceInstance);
        ////}

        ////[TestMethod]
        ////[DeploymentItem("DynConDevCorp.OpenArch.SmartData.Core.dll")]
        ////public void Initialize_UnitTest()
        ////{
        ////    PrivateObject param0 = GetPrivateObject();
        ////    MetaEntity_Accessor target = new MetaEntity_Accessor(param0); 
        ////    ISmartEntity entity = new TestSmartEntity(); 
        ////    target.Initialize(entity);
        ////}

        internal static PrivateObject GetPrivateObject()
        {
            Type entityType = typeof(TestSmartEntity);
            return new PrivateObject(new SmartMetaEntity(entityType));

        }

        [TestMethod]
        [Ignore]
        [DeploymentItem("DynConDevCorp.OpenArch.SmartData.Core.dll")]
        public void GetAutoFields_UnitTest()
        {
            PrivateObject param0 = GetPrivateObject();
            MetaEntity_Accessor target = new MetaEntity_Accessor(param0); 
            object rawActual = target.GetAutoFields();
            Assert.IsNotNull(rawActual);
            Assert.IsInstanceOfType(rawActual, typeof (List<SmartMetaAutoField>));
        }

        [TestMethod]
        [DeploymentItem("DynConDevCorp.OpenArch.SmartData.Core.dll")]
        public void CalculateType_UnitTest()
        {
            Type propertyType = typeof (ISmartField<double>);
            Type rootType;
            Type rootTypeExpected = typeof (SmartField<>);
            Type specializationType;
            Type specializationTypeExpected = typeof (Double);
            Type actualType;
            Type actualTypeExpected = typeof (SmartField<Double>);
            MetaEntity_Accessor.CalculateType(propertyType, out rootType, out specializationType, out actualType);
            Assert.AreEqual(rootTypeExpected, rootType);
            Assert.AreEqual(specializationTypeExpected, specializationType);
            Assert.AreEqual(actualTypeExpected, actualType);
        }

        [TestMethod]
        [DeploymentItem("DynConDevCorp.OpenArch.SmartData.Core.dll")]
        public void MetaEntityConstructor_UnitTest()
        {
            Type entityType = typeof (TestSmartEntity);
            MetaEntity_Accessor target = new MetaEntity_Accessor(entityType);
            Assert.IsNotNull(target);
        }
    }
}
